package com.trustasia.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.trustasia.model.UserModel;
import com.trustasia.service.UserService;

@Controller("userAction")
@RequestMapping("/reg")
@SessionAttributes({"u"})
public class UserAction {
	
	@Resource
	private UserService userService;
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	
	@RequestMapping(params={"method=find"})
	public String reg1(HttpServletRequest req){
		System.out.println("control -- reg1-----");
		System.out.println("#########################"+req.getAttribute("u"));
		//获取session中的u值
		userService.add((String)req.getSession().getAttribute("u"));
		return "index";
	}

	@RequestMapping(params={"method=login"})
	public String reg(@ModelAttribute("u") String name,ModelMap map){
		System.out.println("control -- userAction-----");
		userService.add(name);
		return "reg";
	}
	
	@RequestMapping(params={"method=reg"})
	public ModelAndView reg2(String uname){
		System.out.println("return ModelAndView ......");
		ModelAndView mav = new ModelAndView();
		mav.setViewName("index");
//		mv.setView(new RedirectView("index"));
		UserModel u = new UserModel();
		u.setName("zhangxiao");
		mav.addObject(u);
		mav.addObject("a", "aaaaaaaaaaa");
		return mav;
	}
}
